package se.dolkow.skola.datasakerhet.client;

import java.io.IOException;

import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.security.cert.X509Certificate;

public class DisconnectingClient {

	
	public static void main(String[] args) {
		if (args.length < 1) {
			System.out.println("You must specify a host (port is optional)");
			System.exit(1);
		}
		
		String host = args[0];
		
		int port = 34567;
		if (args.length > 1) {
			port = Integer.parseInt(args[1]);
		}
		
		System.out.println("Connecting to " + host + ":" + port);
		try {
			SSLSocket socket = (SSLSocket)SSLSocketFactory.getDefault().createSocket(host, port);
			
			SSLSession session = socket.getSession();
			
			X509Certificate servercert = (X509Certificate)session.getPeerCertificates()[0];
			System.out.println(servercert.getSubjectDN().getName());
			
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
